package com.xseagull.account.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xseagull.account.common.ResultData;
import com.xseagull.account.entity.User;
import com.xseagull.account.service.IUserService;


@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {

	@Autowired
	private IUserService userService;
	
	@Value("${sleep:0}")
	private int sleep;
	
	@GetMapping("/test")
	public String test() {
		return "sleep：" + sleep;
	}

	/**
	 * 新增用户信息
	 */
	@PostMapping("/insert")
	public ResultData insert(@RequestBody User user) {
		return userService.insert(user);
	}

	/**
	 * 更新用户信息
	 */
	@PostMapping("/update")
	public ResultData update(User user) {
		return userService.update(user);
	}
	
	@GetMapping("/getOneParameter")
    public ResultData getOneParameter(int number){
		return ResultData.success(number);
	}
	
	@GetMapping("/getMoreParameter")
    public ResultData getMoreParameter(int number, String name){
		return ResultData.success(name);
	}
	
	@GetMapping("/getPathVariable/{number}")
    public ResultData getPathVariable(@PathVariable int number){
		return ResultData.success(number);
	}
	
	@PostMapping("/postOneParameter")
    public ResultData postOneParameter(int number){
		return ResultData.success(number);
	}
	
	@PostMapping("/postMoreParameter")
    public ResultData postMoreParameter(int number, String name){
		return ResultData.success(name);
	}
	
	@PostMapping("/postPathVariable/{number}")
    public ResultData postPathVariable(@PathVariable int number){
		return ResultData.success(number);
	}
	
	@PostMapping("/postObject")
	public ResultData postObject(@RequestBody User user) {
		return ResultData.success(user.getAvatar());
	}
	
	@GetMapping("/testGet")
    public ResultData testGet(int number, String userId){
		return ResultData.success(userId);
	}
	
	@PostMapping("/testPost")
    public ResultData testPost(int number, String userId){
		return ResultData.success(userId);
	}
}
